var fs = require("fs"),
    PATH = require("path"),
    exec = require("child_process").exec,
    Q = require('q');

//TODO 增加目录检查
exports.mkdir = function(path) {
    var defer = Q.denodeify(fs.mkdir)(path);
    defer.then(function() {
        console.log("succeed : mkdir " + path);
    });
    defer.fail(function(err) {
        console.log(err);
    });
    return defer;
};

exports.rm = function(path) {
    var stat = fs.statSync(path);
    if(stat.isDirectory()) {
        fs.readdirSync(path).forEach(function(url) {
            exports.rm(PATH.join(path, url));   //递归检查目录，删除字文件夹
        });
        fs.rmdirSync(path);
    } else if(stat.isFile()) {
        fs.unlinkSync(path);
    }
};